/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package Personne;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Morgan
 */
@Stateless
public class PersonneCheck implements PersonneCheckLocal {
    @PersistenceContext(unitName = "TP-Personne-EJB-ejbPU")
    private EntityManager em;
    
    @Override
    public Boolean check(String login, String password) {
        Query query = em.createQuery("select Object(p) from Personne p where p.login = :login p.password=:password");
        query.setParameter("login", login);
        query.setParameter("password", password);
        
        return query.getResultList().size() > 0;
    }

    @Override
    public Personne getPersonne(String login) {
        return (Personne) em.createQuery("select Object(p) from Personne p where p.login = ?1").setParameter(1, login).getSingleResult();
    }
    
}
